package com.li.Demo;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

/** 请完成下面这个函数，实现题目要求的功能 **/
 /** 当然，你也可以不按照这个模板来作答，完全按照自己的想法来 ^-^  **/
    static long min(int[] from, int[] to) {
    	int length = from.length+to.length;
    	int num = 0;
    	int j =0;
    	int k = 0;
    	int i = 0;
    	int[] result = new int[length];
    	while(i < length && k < to.length && j < from.length){
    		int flag = 0;
    		int temp = Math.abs(from[j]-to[k]);
    		if(j+1<from.length){
    			flag = temp >= Math.abs(from[j]-from[j+1]) ? 0:1;
    		}
    		if(k+1<to.length){
    			if(flag ==0 ){
    				flag = temp >= Math.abs(to[k]-to[k+1]) ? 0:2;
    			}else{
    				flag = Math.abs(from[j]-from[j+1]) >= Math.abs(to[k]-to[k+1]) ? 1:2;
    			}
    		}
    		if(flag == 0){
    			result[i++] = from[j++];
    			result[i++] = to[k++];
    		}else if(flag == 1){
    			result[i++] = from[j++];
    			result[i++] = from[j++];
    		}else{
    			result[i++] = to[k++];
    			result[i++] = to[k++];
    		}
    		
    	}
    	while(i < length &&j < from.length){
    		result[i++] = from[j++];
    	}
    	while(i < length &&k < to.length){
    		result[i++] = to[k++];
    	}
    	int i2 = 0;
    	while(i2<length){
    		if(i2+1<length){
    			num += result[i2]*result[i2+1];
    			i2+=2;
    		}else{
    			num += result[i2]; 
    			i2+=1;
    		}
    	}
    	System.out.println(Arrays.toString(result));
    	return num;
    }

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        long res;
            
        int _from_size = 0;
        _from_size = Integer.parseInt(in.nextLine().trim());
        int[] _from = new int[_from_size];
        int _from_item;
        for(int _from_i = 0; _from_i < _from_size; _from_i++) {
            _from_item = Integer.parseInt(in.nextLine().trim());
            _from[_from_i] = _from_item;
        }
        
        int _to_size = 0;
        _to_size = Integer.parseInt(in.nextLine().trim());
        int[] _to = new int[_to_size];
        int _to_item;
        for(int _to_i = 0; _to_i < _to_size; _to_i++) {
            _to_item = Integer.parseInt(in.nextLine().trim());
            _to[_to_i] = _to_item;
        }
  
        res = min(_from, _to);
        System.out.println(String.valueOf(res));  

    }
}